//
//  PopupViewController.m
//  Pods
//
//  Created by Qianxia on 2016/12/30.
//
//

#import "PopupViewController.h"

@interface PopupViewController ()

@end

@implementation PopupViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    // 执行动画
    [self showWithAnimations:nil completion:nil];
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:NO];
}

- (void)showWithAnimations:(void (^)(void))animations completion:(void (^)(BOOL))completion {
    
    self.transformView.transform = CGAffineTransformMakeScale(0.01, 0.01);
    self.view.backgroundColor = [UIColor colorWithWhite:0 alpha:0];
    
    [super showWithAnimations:^{
        self.view.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
        self.transformView.transform = CGAffineTransformMakeScale(1.05, 1.05);
        
    } completion:^(BOOL finished) {
        
        [UIView animateWithDuration:0.08 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
            self.transformView.transform = CGAffineTransformIdentity;
        } completion:nil];
        
    }];
    
    
}

- (void)hiddenWithAnimations:(void (^)(void))animations completion:(void (^)(BOOL))completion {
    
    self.view.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
    self.transformView.transform = CGAffineTransformMakeScale(1.05, 1.05);
    
    [super hiddenWithAnimations:^{
        self.transformView.transform = CGAffineTransformMakeScale(0.01, 0.01);
        self.view.backgroundColor = [UIColor colorWithWhite:0 alpha:0];
    } completion:^(BOOL finished) {
        
        // 主线程执行
        dispatch_async(dispatch_get_main_queue(), ^{
            [self dismissViewControllerAnimated:NO completion:^{
                
                if (completion) {
                    
                    completion(YES);
                }
            }];
        });
    }];
}

- (void)hidden {
    [self hiddenWithAnimations:nil completion:nil];
}

@end
